<template>
  <div v-if="showDom">
    <div class="mask">
    </div>
    <div class="content">
        <div class="toggle-c" >
          <div class="show-login" >
            <div class="show-login-tile">
              修改密码
            </div>
            <div class="show-login-input">
              <!-- <div class="login-username">
                <img src="../../assets/beneform4j/login/login_icon_user_sel.png" alt="">
                <input type="password" v-model="oldPwd" placeholder="请输入原密码">
              </div> -->
              <div class="login-pwd">
                <img src="../../assets/beneform4j/login/login_icon_key_sel.png" alt="">
                <input type="password" v-model="userPwd" placeholder="请输入新密码">
              </div>
              <div class="login-pwd">
                <img src="../../assets/beneform4j/login/login_icon_key_sel.png" alt="">
                <input type="password" v-model="userPwd2" placeholder="请再次输入新密码">
              </div>
            </div>
            <div class="login-boottom-action">
              <el-button @click="login" style="width: 280px;height: 40px" type="primary">确定</el-button>
            </div>
            <div @click="cancel" class="show-toggle-user color">
                取消
              </div>
          </div>

        </div>
    </div>
  </div>
</template>

<script>

import { changeUserPwd, getSessionUserApi } from '../api/login'
export default {
  data() {
    return {
      showBack: true,
      userPwd: '',
      userPwd2: '',
      // userName: '',
      oldPwd: '',
      showDom: false,
      // userId: ''
    }
  },
  mounted: function() {
    // document.body.style.overflow = 'hidden'
    /**
     * 获取用户信息
     */

    // this.userName = this.$store.state.user.name
    // this.userId = this.$store.state.user.userId
    // console.log(this.userName , this.userId)

  },
  destroyed() {
    // document.body.style.overflow = 'initial'
  },
  methods: {
    show() {
      this.showDom = true
    },
    hidden() {
      this.showDom = false
    },
    login() {
      this.userPwd
      this.userPwd2
      this.oldPwd
      // if (!this.oldPwd) {
      //   this.$message({
      //     message: '请输入原密码',
      //     type: 'error'
      //   })
      //   return
      // }
      if (!this.userPwd || !this.userPwd2) {
        this.$message({
          message: '请输入新密码',
          type: 'error'
        })
        return
      }
      if (this.userPwd !== this.userPwd2) {
        this.$message({
          message: '重复输入的密码不一致',
          type: 'error'
        })
        return
      }
      if (this.userPwd.length < 6) {
        this.$message({
          message: '密码长度必须大于6个字符',
          type: 'error'
        })
        return
      }
      changeUserPwd(this.$store.state.user.name, this.oldPwd, this.userPwd2, this.$store.state.user.userId).then(response => {
        if (response.success) {
          this.$message({
            message: '密码修改成功',
            type: 'success'
          })
          this.hidden()
        }
      })
      // 登录请求
      // loginByUsername(this.userName, this.userPwd).then((response) => {
      //   if (response.success) {
      //     this.$store.dispatch('LoginByUsername', response.data).then(() => {
      //       this.loading = false
      //     })
      //     document.body.style.overflow = 'initial'
      //     this.$store.dispatch('ToggleOnlineStatusNormal').then(() => {
      //       this.showBack = false
      //       this.userPwd = ''
      //       this.$message({
      //         message: '登录成功',
      //         type: 'success'
      //       })
      //     })
      //   }
      // })
    },
    cancel() {
      this.hidden()
    }
  }
}
</script>

<style scoped>
/* @import '../style/animation.css'; */
.content{
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.mask{
  background: rgba(0, 0, 0, 0.25);
  position: fixed;
}
.toggle-c{
  width: 400px;
  height: 373px;
  margin: 0 auto;
  position: relative;
  background: #FFF;
  transition: 0.5s ease all;
}
.header-title{
  margin: 20px 16px;
  margin-bottom: 0;
  border-bottom: 1px dotted #e9e9e9;
  font-weight: bold;
  padding-bottom: 20px;
}
.body-img{
  margin: 20px 0;
}
.alert-info{
  padding-bottom: 20px;
  border-bottom: 1px dotted #e9e9e9;
  margin-left: 20px;
  margin-right: 20px;
}
.boottom-action{
  margin: 20px;
}
.header-title>.float-l>img{
  position: relative;
  top: 3px;
}

.show-back{
  transform: rotateY(180deg);
}
.show-front{
  transform: rotateY(0deg);
}
.show-back .show-login{
  transform: rotateY(180deg);
}
.show-front .show-login{
  transform: rotateY(0deg);
}
.show-login-tile{
  font-weight: bold;
  font-size: 18px;
  margin-top: 10px;
  text-align: center;
}
.show-login-input {
  margin: 0 64px;
}
.show-login-input>div{
  position: relative;
}
.show-login-input input{
  -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: none;
    padding: 0 40px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
    border-top: none;
    border-left: none;
    border-right: none;
}
.login-pwd{
  margin-top: 14px;
}
.login-boottom-action{
  margin-top: 20px;
}

.show-toggle-user{
  cursor: pointer;
  /* margin-top: 20px; */
}
.show-login-input>div>img{
  position: absolute;
  left: 10px;
  top: 20px;
}
</style>
